<meta meta="限时抢购设置" args="data"/>
<style>

</style>
<form class="form-horizontal" id="form" s="form,datac,nda,valid"
			s-data="data"
			style="width: 600px;">
	<div class="form-group">
		<label class="col-sm-3 control-label">分享链接</label>
		<div class="col-sm-9">
			<input autocomplete="off" type="text" min="1" class="form-control" name="shareUrl" placeholder=""/>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">分享标题</label>
		<div class="col-sm-9">
			<input autocomplete="off" type="text" min="1" class="form-control" name="shareTitle" placeholder=""
						 s-valid-error="require()"/>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">分享描述</label>
		<div class="col-sm-9">
			<input autocomplete="off" type="text" min="1" class="form-control" name="shareDescription" placeholder=""/>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">分享文案</label>
		<div class="col-sm-9">
			<textarea row="3" autocomplete="off" type="text" min="1" class="form-control" name="shareText" placeholder=""></textarea>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">活动规格</label>
		<div class="col-sm-9">
			<textarea class="form-control" name="rules" rows="5" placeholder="多个规则用换行隔开"></textarea>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-3 control-label">分享图片</label>
		<div class="col-sm-9">
			<div s="tpl" id="icon" s-click="selectIcon()">
				<img src="{%=this.shareThumbUrl || 'images/upload-bg.jpg'%}" class="qrcode-pic"
						 style="max-width: 200px; max-height: 200px;"/>
				<input autocomplete="off" type="hidden" name="shareThumbUrl" value="{%=this.shareThumbUrl%}"/>
			</div>
		</div>
	</div>

	<div class="form-group">
		<label class="col-sm-3 control-label">抢购场次</label>
		<div class="col-sm-9">
			<table class="table table-striped table-condensed table-bordered">
				<thead>
				<tr>
					<th>场次</th>
					<th>时间</th>
					<th class="text-right">操作</th>
				</tr>
				</thead>
				<tbody s="nda,loop" id="list" s-data-filter="'seasonList'">
				<tr s-loop-role="row" s="datac">
					<td>
						<input autocomplete="off" type="text" class="form-control input-sm title" s-valid-error="require()"
									 name="title"/>
					</td>
					<td>
						<select class="form-control input-sm time" name="time">
							<option value="00:00">00:00</option>
							<option value="08:00">08:00</option>
							<option value="09:00">09:00</option>
							<option value="10:00">10:00</option>
							<option value="11:00">11:00</option>
							<option value="12:00">12:00</option>
							<option value="13:00">13:00</option>
							<option value="14:00">14:00</option>
							<option value="15:00">15:00</option>
							<option value="16:00">16:00</option>
							<option value="17:00">17:00</option>
							<option value="18:00">18:00</option>
							<option value="19:00">19:00</option>
							<option value="20:00">20:00</option>
							<option value="21:00">21:00</option>
							<option value="22:00">22:00</option>
							<option value="23:00">23:00</option>
							<option value="24:00">24:00</option>
						</select>
					</td>
					<td class="text-right">
						<a href="javascript:;" class="btn btn-danger btn-outline  btn-sm"
							 s-click="this.node.parent().parent().remove()">删除</a>
					</td>
				</tr>
				</tbody>
				<tfoot>
				<tr>
					<td colspan="3">
						<a href="javascript:;" class="btn btn-primary btn-xs" s-click="addSeason()">新增场次</a>
					</td>
				</tr>
				</tfoot>
			</table>
		</div>
	</div>
</form>
<script type="text/javascript">
	S.getContent = function () {
		var deferred = $.Deferred();
		$form.validate().done(function () {
			var obj = Smart.serializeToObject($form.node)
			var data = []
			obj.seasonList = data
			var titleNodes = S.node.find(".title")
			var timeNodes = S.node.find('.time')
			titleNodes.each(function (i) {
				data.push({
					title: $(this).val(),
					time: timeNodes.eq(i).val()
				})
			})
			deferred.resolve(obj)
		})
		return deferred;
	}

	function addSeason() {
		$list.addRows([{}])
	}

	S.on('s-ready', function () {
		$list.node.sortable()
	})

	function selectIcon() {
		S.popupOpen("/oss/objects-selector.html", {prefix: 'operation'}).done(function (datas) {
			if (datas) {
				var icon = datas[0];
				$icon.data({
					shareThumbUrl: icon.url,
				})
			}
		})
	}
</script>